package com.upay.android.client.adapter;

import java.util.List;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.upay.android.client.R;
import com.upay.domain.group.Group;


public class GroupArrayAdapter extends ArrayAdapter<Group> {
	
	/* ---- Instance Variables ---- */
	private Activity context = null;
	private List<Group> groups = null;

	/* ---- Constructors ---- */
	public GroupArrayAdapter(Activity context, List<Group> groups) {
		super(context, R.layout.groupsubscribedrowlayout, groups);
		this.context = context;
		this.groups = groups;
	}
	
	/* ---- Business Methods ---- */
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		
		if (convertView == null) {
			LayoutInflater inflator = context.getLayoutInflater();
			view = inflator.inflate(R.layout.groupsubscribedrowlayout, null);
			final ViewHolder viewHolder = new ViewHolder();
			viewHolder.group = (TextView) view.findViewById(R.id.registered_group_row_group);
			viewHolder.policy = (TextView) view.findViewById(R.id.registered_group_row_policy);
			viewHolder.balance = (TextView) view.findViewById(R.id.registered_group_row_balance);
			view.setTag(viewHolder);
		} else {
			view = convertView;
		}
		ViewHolder holder = (ViewHolder) view.getTag();
		Group group = groups.get(position);
		holder.group.setText(group.getName());
		holder.group.setTextColor(Color.rgb(51, 181, 229));
		//holder.group.setTextAppearan8ce(getContext(), android.R.style.TextAppearance_DeviceDefault_Large);
		holder.group.setTextSize(18);
		holder.policy.setText(group.getGroupPolicy().getName());
		holder.balance.setText(group.getBalance() == null ? "0.00" : group.getBalance().toString());
		return view;
	}
	

	static class ViewHolder {
		protected TextView group;
		protected TextView policy;
		protected TextView balance;
	}


	/* ---- Getters and Setters ---- */

	/**
	 * @return the context
	 */
	public Activity getContext() {
		return context;
	}



	/**
	 * @param context the context to set
	 */
	public void setContext(Activity context) {
		this.context = context;
	}



	/**
	 * @return the groups
	 */
	public List<Group> getGroups() {
		return groups;
	}



	/**
	 * @param groups the groups to set
	 */
	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}

	

	
	
	

}
